
-module(print).

%%
%% Include files
%%
-include("database.hrl").
-include_lib("stdlib/include/qlc.hrl").
%%
%% Exported Functions
%%
-export([out/1, print_company_stocks/1 , print_user_stocks/1, print_user_favorites/1,
		 print_bid_queue/1, print_ask_queue/1, print_search_name/2, print_user_bid/1, 
		 print_user_ask/1,print_rank/0, print_search_domain/2,roundTo3/1]).

-import(lists, [map/2, foldl/3, reverse/1]).

-define(elog(X,Y), error_logger:info_msg("*elog ~p:~p: " X,
                                         [?MODULE, ?LINE | Y])).

%%% Possible to call mnesia in another way
-define(MNESIA(Mod, Args), apply(mnesia, Mod, Args)).
%%-define(MNESIA(Mod, Args), fdapi:call_in_master(mnesia, Mod, Args)).


%-----------------------------------------------------------------------------------------------------------------%
%---								round																					  
%-----------------------------------------------------------------------------------------------------------------%
roundTo3(Y)->
	Round=erlang:round(Y*1000),
	%io:format("Round ~p ~n",[Round]),
	Res =Round/1000,
	%io:format("Res ~p ~n",[Res]),
	Res.
%-----------------------------------------------------------------------------------------------------------------%
%---								out																					  
%-----------------------------------------------------------------------------------------------------------------%
out(A)->
	ok.



%-----------------------------------------------------------------------------------------------------------------%
%---						print_search_name																						  
%-----------------------------------------------------------------------------------------------------------------%
print_search_name(StockName,UserId)->
	io:format("stock name:~p , userId: ~p~n",[StockName,UserId]),
	
	Res= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 	
					  string:str(string:to_lower(X#company_stocks.company_name), string:to_lower(StockName))>0])),
	%io:format("Res: ~p~n", Res),
	print_comps(Res, "",UserId).



%-----------------------------------------------------------------------------------------------------------------%
%---						print_search_domain																						  
%-----------------------------------------------------------------------------------------------------------------%
print_search_domain(StockDomain,UserId)->
	io:format("StockDomain:~p , userId: ~p~n",[StockDomain,UserId]),
	
	Res= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 	
					  string:str(string:to_lower(a2l(X#company_stocks.domain)), string:to_lower(StockDomain))>0])),
	%io:format("Res: ~p~n", Res),
	print_comps(Res, "",UserId).





%-----------------------------------------------------------------------------------------------------------------%
%---						print_user_ask																						  
%-----------------------------------------------------------------------------------------------------------------%
print_user_ask(UserId)->
	Res= do(qlc:q([X||X<-mnesia:table(ask_queue),
				 		X#bid_queue.user_id==UserId 
					    ])),
	print_user_ask(Res, "", UserId).
	

print_user_ask([] , Str, UserId)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td>  </td>"
						,"<td>  </td>"
						,"<td>  </td>"
						,"<td>  </td>"
						"<td>"
						,"</td> </tr>"]),
	List1;

print_user_ask([Ask|[]] , Str, UserId)->
	[Comp]= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 		X#company_stocks.id==Ask#ask_queue.stock_id
					    ])),
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; text-align: center;'><a  href='PortfolioScreen.yaws?userId=",UserId,"' onclick='update(",Ask#ask_queue.ask_id,",",Ask#ask_queue.stock_id, ")'><img style='border: 0px solid ; width: 46px; height: 40px;' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.company_name,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.domain,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Ask#ask_queue.amount,"<br>"
            			,"</td>"
											
						,"<td style='vertical-align: top;'>",Ask#ask_queue.price,"<br>"
						,"</td> </tr>"]),
	List1;

print_user_ask([Ask|Rest], Str, UserId)->
[Comp]= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 		X#company_stocks.id==Ask#ask_queue.stock_id
					    ])),
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; text-align: center;'><a  href='PortfolioScreen.yaws?userId=",UserId,"' onclick='update(",Ask#ask_queue.ask_id,",",Ask#ask_queue.stock_id, ")'><img style='border: 0px solid ; width: 46px; height: 40px;' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.company_name,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.domain,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Ask#ask_queue.amount,"<br>"
            			,"</td>"
											
						,"<td style='vertical-align: top;'>",Ask#ask_queue.price,"<br>"
						,"</td> </tr>"]),
	print_user_ask(Rest,List1,UserId).



%-----------------------------------------------------------------------------------------------------------------%
%---						print_user_bid																						  
%-----------------------------------------------------------------------------------------------------------------%
print_user_bid(UserId)->
	Res= do(qlc:q([X||X<-mnesia:table(bid_queue),
				 		X#bid_queue.user_id==UserId 
					    ])),
	print_user_bid(Res, "", UserId).


print_user_bid([] , Str, UserId)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td>  </td>"
						,"<td>  </td>"
						,"<td>  </td>"
						,"<td>  </td>"
						"<td>"
						,"</td> </tr>"]),
	List1;

print_user_bid([Bid|[]] , Str, UserId)->
	[Comp]= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 		X#company_stocks.id==Bid#bid_queue.stock_id
					    ])),
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; text-align: center;'><a  href='PortfolioScreen.yaws?userId=",UserId,"' onclick='update(",Bid#bid_queue.bid_id,",",Bid#bid_queue.stock_id, ")'><img style='border: 0px solid ; width: 46px; height: 40px;' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.company_name,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.domain,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Bid#bid_queue.amount,"<br>"
            			,"</td>"
											
						,"<td style='vertical-align: top;'>",Bid#bid_queue.price,"<br>"
						,"</td> </tr>"]),
	List1;

print_user_bid([Bid|Rest], Str, UserId)->
[Comp]= do(qlc:q([X||X<-mnesia:table(company_stocks),
				 		X#company_stocks.id==Bid#bid_queue.stock_id
					    ])),
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; text-align: center;'><a  href='PortfolioScreen.yaws?userId=",UserId,"' onclick='update(",Bid#bid_queue.bid_id,",",Bid#bid_queue.stock_id, ")'><img style='border: 0px solid ; width: 46px; height: 40px;' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.company_name,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Comp#company_stocks.domain,"<br>"
            			,"</td>"
						,"<td style='vertical-align: top;'>",Bid#bid_queue.amount,"<br>"
            			,"</td>"
											
						,"<td style='vertical-align: top;'>",Bid#bid_queue.price,"<br>"
						,"</td> </tr>"]),
	print_user_bid(Rest,List1,UserId).



%-----------------------------------------------------------------------------------------------------------------%
%---			print_Rank																						  
%-----------------------------------------------------------------------------------------------------------------%
print_rank()->
	Str = [],

	Users_Vals= do(qlc:q([X||X<-mnesia:table(users),X#users.value > 0])),
			
			
		Fun = 
			fun(U1, U2) -> 
				if U1#users.value =< U2#users.value ->false;
					U1#users.value > U2#users.value->true
				end
			end,	
	Rank1=lists:sort(Fun, Users_Vals),
    	
	
	case Rank1 of 
		([Rank|Rest])->
			List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Rank#users.id, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.name, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.value, "<br>"
						,"</td></tr>"]),
			print_rank(Rest,List1);
		
	([Rank|[]])->
	
			List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Rank#users.id, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.name, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.value, "<br>"
						,"</td></tr>"]),
			List1;
		([])->List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'> <br>"
						,"</td></tr>"]),
			List1,
	io:format("list: ~p ~n",[List1])
	end
.
		
print_rank(Rest1,Str)->		
	case Rest1 of 
		([Rank|Rest])->
			List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Rank#users.id, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.name, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.value, "<br>"
						,"</td></tr>"]),
			print_rank(Rest,List1);
		
	([Rank|[]])->
	
			List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Rank#users.id, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.name, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Rank#users.value, "<br>"
						,"</td></tr>"]),
			List1;

	([])->List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'> <br>"
						,"</td></tr>"]),
			List1
	end.

%-----------------------------------------------------------------------------------------------------------------%
%---						print_bid_queue																						  
%-----------------------------------------------------------------------------------------------------------------%
print_bid_queue(StockName)->
	Res= do(qlc:q([X||X<-mnesia:table(bid_queue),
				 
					  Y<-mnesia:table(company_stocks),
					  Y#company_stocks.company_name==StockName,
					  X#ask_queue.stock_id==Y#company_stocks.id ])),
	print_bid_queue(Res, "").

%-----------------------------------------------------------------------------------------------------------------%
%---			print_bid_queue																							  
%-----------------------------------------------------------------------------------------------------------------%
print_bid_queue([] , Str)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'><br>"
						,"</td> </tr>"]),
	List1;

print_bid_queue([Bid|[]] , Str)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Bid#bid_queue.amount, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Bid#bid_queue.price, "<br>"
						,"</td> </tr>"]),
	List1;

print_bid_queue([Bid|Rest], Str)->

		List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Bid#bid_queue.amount, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Bid#bid_queue.price, "<br>"
						,"</td> </tr>"]),

	print_bid_queue(Rest,List1).


%-----------------------------------------------------------------------------------------------------------------% 
	%								print_ask_queue
%-----------------------------------------------------------------------------------------------------------------%
print_ask_queue(StockName)->
	Res= do(qlc:q([X||X<-mnesia:table(ask_queue),
				 
					  Y<-mnesia:table(company_stocks),
					  Y#company_stocks.company_name==StockName,
					  X#ask_queue.stock_id==Y#company_stocks.id ])),
	print_ask_queue(Res, "").


%-----------------------------------------------------------------------------------------------------------------%
%---							print_ask_queue																						  
%-----------------------------------------------------------------------------------------------------------------%
print_ask_queue([] , Str)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'><br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'><br>"
						,"</td> </tr>"]),
	List1;

print_ask_queue([Ask|[]] , Str)->
	
	List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Ask#ask_queue.amount, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Ask#ask_queue.price, "<br>"
						,"</td> </tr>"]),
	List1;

print_ask_queue([Ask|Rest], Str)->

		List1= lists:concat([Str, "<tr>"
						,"<td style='vertical-align: top; width: 30px; height: 20px; white-space: nowrap;'>" ,Ask#ask_queue.amount, "<br>"
						,"</td>"
						,"<td style='vertical-align: top; width: 30px; height: 20px;'>", Ask#ask_queue.price, "<br>"
						,"</td> </tr>"]),

	print_ask_queue(Rest,List1).


%-----------------------------------------------------------------------------------------------------------------%
%---							print_user_favorites																							  
%-----------------------------------------------------------------------------------------------------------------%
print_user_favorites(UserId)->
	Res= do(qlc:q([X||X<-mnesia:table(favorites),
				 X#favorites.user_id==UserId])),
	print_user_favorites(Res, "", UserId).

%-----------------------------------------------------------------------------------------------------------------%
%---							print_user_favorites																						
%-----------------------------------------------------------------------------------------------------------------%
print_user_favorites([], Str, UserId)->
	"<tr><td></td><td></td></tr>";
print_user_favorites([Attr|[]], Str, UserId)->
	[{Comp_name, Comp_id}]=do(qlc:q([{X#company_stocks.company_name, X#company_stocks.id}|| X<-mnesia:table(company_stocks),
														 X#company_stocks.id==Attr#favorites.stock_id])),
%	io:format("~p", [Comp_name]),
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='go to stock' href='TradeScreen.yaws?name=" ,Comp_name ,
						 "&stockID=",Comp_id,"&userId=",UserId,"' name='id' value=", Attr#favorites.stock_id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp_name, "</td> ",

		
						"</tr> "]),
	List1;
print_user_favorites([Attr|Rest], Str, UserId)->
	[{Comp_name, Comp_id}]=do(qlc:q([{X#company_stocks.company_name, X#company_stocks.id}|| X<-mnesia:table(company_stocks),
														 X#company_stocks.id==Attr#favorites.stock_id])),
%	io:format("~p", [Comp_name]),
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='go to stock' href='TradeScreen.yaws?name=" ,Comp_name ,"&stockID=",Comp_id,"&userId=",UserId,"' name='id' value=", Attr#favorites.stock_id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp_name, "</td> "

		
						"</tr> "]),
	print_user_favorites(Rest,List1, UserId).



%-----------------------------------------------------------------------------------------------------------------%
%---							print_user_stocks																						   
%-----------------------------------------------------------------------------------------------------------------%
print_user_stocks(UserId)->
	io:format("Uid ~p ~n", [UserId]),
	Res= do(qlc:q([X||X<-mnesia:table(user_stock_table),
				 X#user_stock_table.user_id==UserId])),
	io:format("Stocks ~p", [Res]),
	print_user_stocks(Res, "", UserId).

%-----------------------------------------------------------------------------------------------------------------%
%---							print_user_stocks																						 
%-----------------------------------------------------------------------------------------------------------------%
print_user_stocks([], Str, UserId)->
	"<tr><td></td><td></td></tr>";

print_user_stocks([Attr|[]], Str, UserId)->
	[{Comp_name, Comp_id}]=do(qlc:q([{X#company_stocks.company_name, X#company_stocks.id}|| X<-mnesia:table(company_stocks),
														 X#company_stocks.id==Attr#user_stock_table.stock_id])),
	%TODO: check again
	[Company]= do(qlc:q([C||C<-mnesia:table(company_stocks),C#company_stocks.id==Comp_id])),
	CurrVal = Company#company_stocks.current_value,
	RoundCuerr = mochinum:digits(roundTo3(CurrVal)),
	RoundPrice = mochinum:digits(roundTo3( Attr#user_stock_table.price)),
%	io:format("~p", [Comp_name]),
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='go to stock' href='TradeScreen.yaws?name=" ,Comp_name ,"&stockID=",Comp_id,"&userId=",UserId,"' name='id' value=", Attr#user_stock_table.stock_id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp_name, "</td> "
					, "<td> ", Attr#user_stock_table.total, "</td> "
					, "<td> ",RoundPrice, "</td> "
					, "<td> ",RoundCuerr,"</td> "
					,"</tr> "]),
	List1;

print_user_stocks([Attr|Rest], Str, UserId)->
	[{Comp_name, Comp_id}]=do(qlc:q([{X#company_stocks.company_name, X#company_stocks.id}|| X<-mnesia:table(company_stocks),
														 X#company_stocks.id==Attr#user_stock_table.stock_id])),
	[Company]= do(qlc:q([C||C<-mnesia:table(company_stocks),C#company_stocks.id==Comp_id])),
	CurrVal = Company#company_stocks.current_value,
	RoundCuerr = mochinum:digits(roundTo3(CurrVal)),
	RoundPrice = mochinum:digits(roundTo3( Attr#user_stock_table.price)),
	%io:format("~p", [Comp_name]),
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='go to stock' href='TradeScreen.yaws?name=" ,Comp_name ,"&stockID=",Comp_id,"&userId=",UserId,"' name='id' value=", Attr#user_stock_table.stock_id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp_name, "</td> "
					, "<td> ", Attr#user_stock_table.total, "</td> "
					, "<td> ", RoundPrice, "</td> "
					, "<td> ",RoundCuerr, "</td> "
					,"</tr> "]),
	print_user_stocks(Rest,List1, UserId).
%-----------------------------------------------------------------------------------------------------------------%
%---									print_company_stocks																							  
%-----------------------------------------------------------------------------------------------------------------%
print_company_stocks(UserId)->
	%io:format("<td>~p</td>~n", [mnesia:transaction(fun()->mnesia:all_keys(company_stocks) end)]), 
	Res= do(qlc:q([X||X<-mnesia:table(company_stocks)])),

	print_comps(Res, "",UserId).


%print_comps([], Str)->
%	S1=io:format("done ~n", []),
%	Str++S1;

%-----------------------------------------------------------------------------------------------------------------%
%---									print_comps																						   
%-----------------------------------------------------------------------------------------------------------------%
print_comps([] , Str,UserId)->
	"";
print_comps([Comp|[]] , Str,UserId)->
%	io:format("First1: ~p~n", [Comp]),
%	S1=io:format("done1? ~p ~n", [Str]),
	X=roundTo3(Comp#company_stocks.current_value),
	 
	
	RoundCuerr = mochinum:digits(X),
	io:format("RoundCuerr ~p ~n", [RoundCuerr]),
	Y=roundTo3( Comp#company_stocks.company_val),
	RoundVal = mochinum:digits(Y),
	io:format("RoundVal ~p ~n", [RoundVal]),
	%TODO: check again
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='wanna buy?' href='TradeScreen.yaws?name=" ,Comp#company_stocks.company_name ,"&stockID=",Comp#company_stocks.id, "&userId=",UserId,"' name='id' value=", Comp#company_stocks.id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp#company_stocks.company_name, "</td> "
					, "<td> ", Comp#company_stocks.id, "</td> "
					, "<td> ", Comp#company_stocks.domain, "</td> "
					, "<td> ", RoundVal, "</td> "
					, "<td> ", RoundCuerr, "</td> "
					, "<td> ", Comp#company_stocks.total_exist, "</td> </tr>"]),

	List1;

print_comps([Comp|Rest], Str,UserId)->
	%S11=io:format("First2: ~p~n", [Comp]),
	%S12=io:format("Rest: ~p~n", [Rest]),
	X=roundTo3(Comp#company_stocks.current_value),
	RoundCuerr = mochinum:digits(X),
	io:format("RoundCuerr ~p ~n", [RoundCuerr]),
	Y=roundTo3( Comp#company_stocks.company_val),
	RoundVal = mochinum:digits(Y),
	io:format("RoundVal ~p ~n", [RoundVal]),
	List1= lists:concat([Str, "<tr>"
					," <td style='vertical-align: top; text-align: center;'><a title='wanna buy?' href='TradeScreen.yaws?name=" ,Comp#company_stocks.company_name ,"&stockID=",Comp#company_stocks.id,"&userId=",UserId,"' name='id' value=", Comp#company_stocks.id , " ><img style='border: 0px solid ; width: 46px; height: 40px;' alt='wanna buy?' src='../pictures/dollar.png' align='middle' hspace='2'></a> </td>"
					," <td> ", Comp#company_stocks.company_name, "</td> "
					, "<td> ", Comp#company_stocks.id, "</td> "
					, "<td> ", Comp#company_stocks.domain, "</td> "
					, "<td> ", RoundVal, "</td> "
					, "<td> ", RoundCuerr, "</td> "
					, "<td> ", Comp#company_stocks.total_exist, "</td> </tr>"]),


	%io:format("done???? ~p ~n", [List1]),

	print_comps(Rest,List1, UserId).

%-----------------------------------------------------------------------------------------------------------------%
%---							do																						   
%-----------------------------------------------------------------------------------------------------------------%
do(Q) ->
    F = fun() -> qlc:e(Q) end,
    {atomic, Val} = mnesia:transaction(F),
    Val.

%-----------------------------------------------------------------------------------------------------------------%
%---							a2l																						  
%-----------------------------------------------------------------------------------------------------------------%
a2l(A) when atom(A) -> atom_to_list(A);
			a2l(L) when list(L) -> L.

%-----------------------------------------------------------------------------------------------------------------%
%---							isFloat																						  
%-----------------------------------------------------------------------------------------------------------------%
isFloat(F) when float(F) -> true;
isFloat(F) -> false.
